package com.epic.dagger.tutorial;

//import javax.inject.Inject;
import jakarta.inject.Inject;
import java.math.BigDecimal;
import java.util.List;

final class DepositCommand implements Command {
    private final Database database;
    private final Outputter outputter;

    @Override
    public String key(){
        return "deposit";
    };

    @Inject
    DepositCommand(Database database, Outputter outputter) {
        this.outputter = outputter;
        this.database = database;
    }

    @Override
    public Result handleInput(List<String> input) {
        System.out.println(input.toString());
        if (input.size() != 2) {
            System.out.println(input.size());
            return Result.invalid();
        }

        Database.Account account = database.getAccount(input.get(0));
        account.deposit(new BigDecimal(input.get(1)));
        outputter.output(account.username() + " now has: " + account.balance());
        return Result.handled();
    }
}
